﻿Imports DevExpress.XtraEditors

Public Class frmOperation
    Public Sub view_list()
        Dim data As DataTable
        data = mysql_query("SELECT *, IF(tb_operasi.id_jenis_operasi = '0', tb_jenis_sql.jenis_sql, tb_jenis_operasi.jenis_operasi) AS tipe, IF(tb_operasi.is_publik = '1','Public','Private') AS akses FROM tb_operasi,tb_host,tb_jenis_operasi,tb_jenis_sql WHERE tb_operasi.id_host = tb_host.id_host AND tb_jenis_operasi.id_jenis_operasi = tb_operasi.id_jenis_operasi AND tb_jenis_sql.id_jenis_sql = tb_operasi.id_jenis_sql AND tb_host.is_local = '1' ORDER BY nama_host, nama_operasi")
        GridControlList.DataSource = data
        If data.Rows.Count > 0 Then
            SimpleButtonEdit.Enabled = True
            SimpleButtonDelete.Enabled = True
            SimpleButtonExport.Enabled = True
        Else
            SimpleButtonEdit.Enabled = False
            SimpleButtonDelete.Enabled = False
            SimpleButtonExport.Enabled = False
        End If
    End Sub

    Private Sub frmOperation_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Cursor = Cursors.WaitCursor
        view_list()
        Cursor = Cursors.Default
    End Sub

    Private Sub SimpleButtonRefresh_Click(sender As Object, e As EventArgs) Handles SimpleButtonRefresh.Click
        Cursor = Cursors.WaitCursor
        view_list()
        Cursor = Cursors.Default
    End Sub

    Private Sub SimpleButtonAdd_Click(sender As Object, e As EventArgs) Handles SimpleButtonAdd.Click
        frmOperation_Form.id_operasi = "-1"
        frmOperation_Form.ShowDialog()
    End Sub

    Private Sub SimpleButtonEdit_Click(sender As Object, e As EventArgs) Handles SimpleButtonEdit.Click
        Try
            frmOperation_Form.id_operasi = CType(GridViewList.GetFocusedRowCellDisplayText("id_operasi").ToString, Long)
            frmOperation_Form.ShowDialog()
        Catch ex As Exception
            XtraMessageBox.Show("Please Select One Item For Editing!" & vbCrLf & ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
    End Sub

    Private Sub SimpleButtonDelete_Click(sender As Object, e As EventArgs) Handles SimpleButtonDelete.Click
        If XtraMessageBox.Show("Are you sure want to delete this operation?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
            Cursor = Cursors.WaitCursor
            Dim id_operasi As String = GridViewList.GetFocusedRowCellDisplayText("id_operasi").ToString
            mysql_non_query(String.Format("DELETE FROM tb_operasi WHERE id_operasi = '{0}'", id_operasi))
            view_list()
            Cursor = Cursors.Default
        End If
    End Sub
End Class